package org.jugile.proto2.domain;

import org.jugile.daims.Bo;
import org.jugile.daims.DomainCore;
import org.jugile.util.Jugile;

public class DomainBase extends DomainCore {

	public synchronized static Domain getDomain() {
		if (domain != null) return (Domain)domain;
		domain = new Domain();
		if (hasdb()) {
			((Domain)domain).loadFromDB();
		}
		return (Domain)domain;
	}

	
	// ====== objects =======
	public Person getPerson(String idstr) { return (Person)get(Person.class,Jugile.parseLongSafe(idstr)); }
	public Person getPerson(long id) { return (Person)get(Person.class,id); }	
	public PersonCollection getPersons() { return (PersonCollection)getAll(Person.class); }
	public Person createPerson() { return (Person)createNew(Person.class); }
	
	public Family getFamily(long id) { return (Family)get(Family.class,id); }	
	public FamilyCollection getFamilies() { return (FamilyCollection)getAll(Family.class); }
	public Family createFamily() { return (Family)createNew(Family.class); }

	// these are needed to know what to load from db
	protected Class<Bo>[] classes() { return classes; }
	private static Class[] classes = {
		Person.class,
		Family.class,
	};

	
}
